using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using OpenNETCF.Windows.Forms.Calendar;
using System.Drawing.Imaging;

namespace OpenNETCF
{
    public partial class AgendaDemo : Form
    {
        Bitmap alarm;
        StaticCalendarDataProvider dataProvider;
        public AgendaDemo()
        {
            using (new OpenNETCF.Windows.Forms.Cursor2())
            {
                InitializeComponent();

                if (Environment.OSVersion.Version >= new Version("5.1"))
                {
                    cal.DataProvider = new POOMCalendarProvider(); //dataProvider;
                }
                else
                {
                    dataProvider = new StaticCalendarDataProvider();
                    dataProvider.Add(new OpenNETCF.Windows.Forms.Calendar.CalendarItem(DateTime.Parse("12/12/05 2:00 PM"), TimeSpan.FromHours(4), null, "Bob's birthday party"));
                    dataProvider.Add(new OpenNETCF.Windows.Forms.Calendar.CalendarItem(DateTime.Parse("12/12/05 3:00 PM"), TimeSpan.FromHours(1), null, "Bachelor party"));
                    dataProvider.Add(new OpenNETCF.Windows.Forms.Calendar.CalendarItem(DateTime.Parse("12/12/05 4:00 PM"), TimeSpan.FromHours(1), null, "One night in Bangkok"));
                    dataProvider.Add(new OpenNETCF.Windows.Forms.Calendar.CalendarItem(DateTime.Parse("12/12/05 6:00 PM"), TimeSpan.FromHours(36), null, "Presidential elections"));
                    cal.DataProvider = dataProvider;
                }
                cal.ItemSelected += new EventHandler(cal_ItemSelected);
                cal.Date = DateTime.Now;// DateTime.Parse("12/12/05");

                //Draw label is called first.  This is used to custom draw the label.
                this.cal.DrawLabel += new OpenNETCF.Windows.Forms.Calendar.DrawLabelHandler(monthCalendar1_DrawLabel);

                //Get the alarm image
                alarm = new Bitmap(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("CalendarSample.alarm.bmp"));
            
            }
        }

        /// <summary>
        /// Custom drawing for the cell.  Can use this to draw an icon to display an appointment etc
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="date"></param>
        /// <param name="rectCell"></param>
        /// <param name="gxCell"></param>
        private void monthCalendar1_DrawLabel(OpenNETCF.Windows.Forms.Calendar.BaseCalendar sender, DateTime date, Rectangle rectCell, Graphics gxCell)
        {

            if (date.Date == DateTime.Now.Date)
            {
                //Draw an icon
                Rectangle dest = new Rectangle(rectCell.X + rectCell.Width - this.alarm.Width,
                    rectCell.Y + rectCell.Height - this.alarm.Height,
                    this.alarm.Width, this.alarm.Height);

                ImageAttributes ia = new ImageAttributes();
                ia.SetColorKey(this.alarm.GetPixel(0, 0), this.alarm.GetPixel(0, 0));
                gxCell.DrawImage(this.alarm, dest, 0, 0, this.alarm.Width, this.alarm.Height, GraphicsUnit.Pixel, ia);

            }

        }


        void cal_ItemSelected(object sender, EventArgs e)
        {
            return;
            if (cal.SelectedItem != null)
            {
                if (cal.SelectedItem.DataObject is Microsoft.WindowsMobile.PocketOutlook.Appointment)
                {
                    (cal.SelectedItem.DataObject as Microsoft.WindowsMobile.PocketOutlook.Appointment).ShowDialog();
                }
                else
                {
                    MessageBox.Show(cal.SelectedItem.Text, "Selected item");
                }
            }
        }
    }
}